package cn.tedu.micro.demo.rabbitmq.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 提前声明预备 2个组件
 * demo-ex fanout
 * demo-queue
 * 绑定
 */
@Configuration
@Slf4j
public class DeclareConfig {
    //声明队列
    @Bean
    public Queue demoQ(){
        //channel.queueDeclare("demo-queue",false,false,false,null);
        QueueBuilder queueBuilder = QueueBuilder.nonDurable("demo-queue");
        return queueBuilder.build();
    }
    //交换机
    @Bean
    public Exchange demoEx(){
        //channel.exchangeDeclare("demo-ex","fanout");
        ExchangeBuilder exBuilder = ExchangeBuilder.fanoutExchange("demo-ex");
        return exBuilder.build();
    }
    //绑定 demo-queue demo-ex ""
    @Bean
    public Binding bindDemoEQ(){
        //channel.queueBind("demo-queue","demo-ex","");
        BindingBuilder.GenericArgumentsConfigurer bindBuilder = BindingBuilder.bind(demoQ()).to(demoEx()).with("");
        return bindBuilder.noargs();
    }
}
